package com.xxgc.vfc.common.error.system;

import cn.dev33.satoken.exception.NotLoginException;
import cn.dev33.satoken.exception.NotRoleException;
import com.xxgc.vfc.api.result.Result;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/*
 *
 *   @Author:SJY
 *   @Date: 2023/11/15-11-15-14:41
 *   权限框架相关异常
 */
@ControllerAdvice
@ResponseBody
public class SaTokenError {

    //拦截到没有登录的异常
    @ExceptionHandler(value = {NotLoginException.class})
    public ResponseEntity<Result> notLoginException(NotLoginException e) {
        return new ResponseEntity<>(
                Result.error().code(401).msg("登录过期请重新登录"),
                HttpStatus.UNAUTHORIZED
        );
    }

    @ExceptionHandler(value = {NotRoleException.class})
    public ResponseEntity<Result> notRoleException(NotRoleException e) {
        return new ResponseEntity<>(
                Result.error().code(403).msg("无权限"),
                HttpStatus.FORBIDDEN
        );
    }


}
